using System;

namespace GeneticAlgorithms.Alphabets
{
    /// <summary>
    /// An alphabet of binary values.
    /// </summary>
    public class BinaryAlphabet : IAlphabet<bool>
    {
        #region IAlphabet<bool> Members

        /// <summary>
        /// Gets the numeric range for the alphabet.
        /// </summary>
        /// <value>
        /// The total number of different values genes
        /// in this alphabet may have.
        /// </value>
        /// <remarks>
        /// This property is used for random gene generation.
        /// </remarks>
        public int Range
        {
            get { return 2; }
        }

        /// <summary>
        /// Converts from an int into a gene value.
        /// </summary>
        /// <param name="value">The numeric value to be converted.</param>
        /// <returns>
        /// A gene that corresponds to the numeric value.
        /// </returns>
        public bool ConvertFromInt(int value)
        {
            if (value >= this.Range)
            {
                throw new ArgumentOutOfRangeException("value");
            }

            return value > 0;
        }

        #endregion
    }
}
